<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" append-to-body>
    <div>
      <el-form ref="showForm" label-position="right" label-width="100px">

        <el-row :gutter="24">
          <el-col :span="9">
            <el-form-item label="费用信息：">
              <el-input v-model="queryParma.fyxx" clearable size="small" placeholder="请输入查询信息" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="是否有效：">
              <el-select v-model="queryParma.sfyxbs" style="position: relative;left: 5px" filterable default-first-option placeholder="请选择有效标识">
                <el-option
                  key="0"
                  label=""
                  value=""
                />
                <el-option
                  key="1"
                  label="是"
                  value="1"
                />
                <el-option
                  key="2"
                  label="否"
                  value="0"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5" align="right">
            <el-button type="primary" :loading="searchloding" @click="getExpanseInfoListPageHandle">查询</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="9">
            <el-form-item label="收费按类型：">
              <el-select v-model="queryParma.sflx" style="position: relative;left: 5px" filterable default-first-option placeholder="请选择收费按类型">
                <el-option
                  key="0"
                  label=""
                  value=""
                />
                <el-option
                  v-for="item in expanseTypeArray"
                  :key="item.code"
                  :label="item.value"
                  :value="item.code"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="收费按模式：">
              <el-select v-model="queryParma.sfms" style="position: relative;left: 5px" filterable default-first-option placeholder="请选择收费按模式">
                <el-option
                  key="0"
                  label=""
                  value=""
                />
                <el-option
                  v-for="item in expanseModelArray"
                  :key="item.code"
                  :label="item.value"
                  :value="item.code"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!--    查询查询部分-->
    <div>
      <el-divider content-position="left"><span style="font-weight: bolder;font-size: 18px">费用项目信息展示</span></el-divider>
      <!--      数据操作按钮-->
      <div style="padding: 10px" align="right">
        <!--        <el-button-group>-->
        <!--          <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>-->
        <!--          <el-button type="danger" icon="el-icon-delete" @click="handleDeleteBatch">批量删除</el-button>-->
        <!--        </el-button-group>-->
      </div>

      <el-table
        v-loading="loading"
        :data="dataSource"
        :border="true"
        align="center"
        empty-text="暂无数据"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
        />
        <el-table-column
          type="index"
          :index="indexMethod"
          label="#"
          width="50"
          align="center"
        />
        <el-table-column
          label="项目名称"
          align="center"
          prop="expenseName"
        />
        <el-table-column
          label="单价"
          header-align="center"
          align="right"
          prop="amountPrice"
        >
          <template slot-scope="{row}">
            {{ row.amountPrice }} /元
          </template>
        </el-table-column>
        <el-table-column
          label="费用类型"
          min-width="100"
          header-align="center"
          align="center"
          prop="expenseType"
        >
          <template slot-scope="{row}">
            {{ getTypeDictsValue(row.expenseType) }}
          </template>
        </el-table-column>
        <el-table-column
          label="费用模式"
          min-width="100"
          header-align="center"
          align="center"
          prop="expenseModle"
        >
          <template slot-scope="{row}">
            {{ getModelDictsValue(row.expenseModle) }}
          </template>
        </el-table-column>
        <el-table-column
          label="优先级"
          min-width="100"
          header-align="center"
          align="center"
          prop="level"
        />
        <el-table-column
          label="注册时间"
          prop="creatTime"
          header-align="center"
          min-width="150"
        />
        <el-table-column
          label="更新时间"
          prop="updateTime"
          header-align="center"
          min-width="150"
        />
        <!--        <el-table-column
          label="是否有效"
          header-align="center"
          align="center"
          min-width="120"
          prop="valiFlag"
        >
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.valiFlag"
              active-value="1"
              inactive-value="0"
              active-color="#13ce66"
              inactive-color="#ff4949"
              @change="switchHandle(scope.row)"
            />
          </template>
        </el-table-column>-->
        <!--        <el-table-column
          label="操作"
          align="center"
          min-width="150"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>-->
      </el-table>
      <div align="center">
        <div style="display: inline-block;width: 60px;height:60px;line-height: 60px;text-align: center;font-size: 15px">
          <span style="text-align: center;line-height: 60px;width: 60px;height:60px;">共{{ dataTotals }}条</span>
        </div>
        <div style="display: inline-block">
          <el-pagination
            :current-page.sync="queryParma.pageIndex"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="queryParma.pageSize"
            layout="total, sizes, prev,next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <div slot="footer" class="dialog-footer" align="center">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="handleConfirm">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { getAllExpanseInfoPage } from '@/api/ht/zffygl/fyxxgl'
const { getDictsList } = require('@/api/dicts')
const { addOneOrBatchPayInfo } = require('@/api/ht/zffygl/zfxxgl')
const { Message } = require('element-ui')
export default {
  name: 'Modal',
  props: {
    expanseTypeArray: {
      type: Array,
      default: () => []
    },
    expanseModelArray: {
      type: Array,
      default: () => []
    },
    householdeCode: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      title: '费用项目信息查询',
      loading: false, // 数据加载显示图标
      formLabelWidth: '150px', // 表单输入框字段宽度
      searchloding: false, // 搜索按钮加载
      dialogFormVisible: false, // 对话框是否显示
      dataSource: {}, // 数据源
      queryParma: {
        pageIndex: 1,
        pageSize: 5,
        fyxx: '',
        sfyxbs: ''
      },
      dataTotals: 0,
      hasselectedIdArray: [] // 选中的数据数组列表
    }
  },
  watch: {
    villageInfo(newdata, prevdata) {
      this.dataSource = newdata
      this.hasSelectedCotyObj.value = this.alldictsInfo.find(item => item.code === newdata.cotyCode).value
      this.title = '小区信息修改' + this.dataSource.id
    }
  },
  methods: {
    showModel() {
      // 展示对话框
      this.getExpanseInfoListPageHandle()
      console.log(this.expanseModelArray)
      this.dialogFormVisible = true
    },
    indexMethod(index) {
      return index + 1 + (this.queryParma.pageIndex - 1) * this.queryParma.pageSize
    },
    getExpanseInfoListPageHandle() {
      this.getExpanseInfoListPage()
    },
    async getExpanseInfoListPage() {
      this.loading = true
      const res = await getAllExpanseInfoPage(this.queryParma)
      const data = res.data.main.dataArray
      const resp = res.data.respOutMsgHeader
      const totals = res.data.main.totalsData
      const currentPage = res.data.main.currentPage
      if (resp.respCode === 200) {
        setTimeout(() => {
          this.searchloding = false
          this.loading = false
        }, 500)
        this.dataSource = data
        this.dataTotals = totals
        this.queryParma.pageIndex = currentPage
      } else {
        Message({
          message: resp.msg || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
        this.loading = false
      }
    },
    getTypeDictsValue(code) {
      return getDictsList(this.expanseTypeArray, code)
    },
    getModelDictsValue(code) {
      return getDictsList(this.expanseModelArray, code)
    },
    handleConfirm() {
      if (this.hasselectedIdArray.length === 0) {
        Message({
          message: '请至少选择一种费用项目进行添加' || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
        return false
      }
      this.addBatchPayInfoHandle()
    },
    addBatchPayInfoHandle() {
      this.addBatchPayInfo()
    },
    async addBatchPayInfo() {
      const res = await addOneOrBatchPayInfo(this.hasselectedIdArray, this.householdeCode)
      const resp = res.data.respOutMsgHeader
      if (resp.respCode === 200) {
        this.dialogFormVisible = false
        this.$emit('reflushPayInfoList')
      } else {
        Message({
          message: resp.msg || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
      }
    },
    handleSelectionChange(selections) {
      const rowIdArray = []
      for (const selection of selections) {
        rowIdArray.push(selection.id)
      }
      this.hasselectedIdArray = rowIdArray
    },
    handleConfirmCoty() {
      this.dataSource.cotyCode = this.hasSelectedCotyObj.code
      this.dialogCotyVisible = false
    },
    handleSizeChange(val) {
      this.queryParma.pageSize = val
      this.getExpanseInfoListPageHandle()
    },
    handleCurrentChange(val) {
      this.queryParma.pageIndex = val
      this.getExpanseInfoListPageHandle()
    },
    reflushDataHandle() {
      // 调用父组件获取方法刷新数据
      this.$emit('reflushDataHandle')
    },
    resetForm() {
      this.queryParma = {
        pageIndex: 1,
        pageSize: 5,
        fyxx: '',
        sfyxbs: ''
      }
    }
  }
}
</script>

<style scoped>
.down-tree{
  height: 350px;
  display: block;
  overflow-y: scroll;
}
</style>
